@extends('public.base')
@section('body')

  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="layui-card-header">修改密码</div>
          <div class="layui-card-body" pad15>
            
            <div class="layui-form" lay-filter="">
              <div class="layui-form-item">
                <label class="layui-form-label">当前密码</label>
                <div class="layui-input-inline">
                  <input type="password" name="oldpassword" lay-verify="required|pass" lay-verType="tips" class="layui-input">
                </div>
                  <div class="layui-form-mid layui-word-aux">6到16个字符</div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">新密码</label>
                <div class="layui-input-inline">
                  <input type="password" name="password" lay-verify="pass" lay-verType="tips" autocomplete="off" id="LAY_password" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">6到16个字符</div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">确认新密码</label>
                <div class="layui-input-inline">
                  <input type="password" name="repassword" lay-verify="repass" lay-verType="tips" autocomplete="off" class="layui-input">
                </div>
                  <div class="layui-form-mid layui-word-aux">6到16个字符</div>
              </div>
                <input type="hidden" name="uid" value="{{UID}}"/>
              <div class="layui-form-item">
                <div class="layui-input-block">
                  <button class="layui-btn" lay-submit lay-filter="form_save">保存</button>
                </div>
              </div>
            </div>
            
          </div>
        </div>
      </div>
    </div>
  </div>

  <script src="{{ADMIN_PATH}}layui/layuiadmin/layui/layui.js"></script>
  <script>
      var save_url='{{url('admin/member/password')}}';
  layui.config({
    base: '{{ADMIN_PATH}}layui/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'form'],function(){
      var $ = layui.$
          ,admin = layui.admin
          ,element = layui.element
          ,layer = layui.layer
          ,laydate = layui.laydate
          ,form = layui.form;

      form.verify({
         pass: [/(.+){6,16}$/, '密码必须6到16位']
          ,content: function(value){
              layedit.sync(editIndex);
          }
      });

      /* 监听提交 */

      //重置密码
      form.on('submit(form_save)', function(obj){
          var field = obj.field;
          console.log(field);
          //确认密码
          if(field.password != field.repassword){
              return layer.msg('两次密码输入不一致');
          }
          if(field.oldpassword==field.password){
              return layer.msg('新密码不能与旧密码一致');
          }
          //请求接口
          $.post(save_url, field, function (res) {
              try {
                  if(res.status==200) {
                      //重新刷新父窗口的数据区
                      layer.msg('保存成功', {icon: 1})
                  }else{
                      layer.msg(res.message);
                  }
              } catch (e) {
                  layer.msg("异常");
              }

          }, "json");

          return false;
      });

  });
  </script>
@stop